<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: lxf
  Date: 2016/7/5
  Time: 11:50
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <title>用户管理</title>
</head>
<body>
<div>
    <form:form commandName="userDTO" action="/back/user/form" method="post" id="userManagerForm">
        <form:hidden path="guid"/>
        <table class="table table-hover">
            <tr>
                <td>用户帐号:</td>
                <td><form:input path="username"/></td>
            </tr>
            <tr>
                <td>用户昵称:</td>
                <td><form:input path="nickname"/></td>
            </tr>
            <tr>
                <td>赋予角色:</td>
                <td class="roleLabel">
                    <form:checkboxes path="roleGuids" items="${roleMap}"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" class="btn btn-primary" value="保存" onclick="checkUserForm()"/>
                    <input type="button" class="btn btn-info" value="返回" onclick="backup()"/>
                </td>
            </tr>
        </table>
    </form:form>
</div>
<myScript>
    <script>
        function checkUserForm() {
            if ($("input[name='username']").val().trim().length <= 0) {
                console.log('please input username');
                return;
            }
            if ($("input[name='nickname']").val().trim().length <= 0) {
                console.log('please input nickname');
                return;
            }
            var roleGuid = $("input[name='roleGuids']:checked");
            if (roleGuid.val() == null) {
                console.log('not select role');
                return;
            }

            $("#userManagerForm").submit();
        }
        function backup() {
            window.location.href = "/back/user/list";
        }
    </script>
</myScript>
</body>
</html>
